#时间格式的转换
from datetime import datetime as dt
import time
from datetime import timedelta

now = dt.now(tz=None)
print(now.strftime("%Y-%m-%d %H:%M:%S")) #datetime -> str
print(now.timestamp()) #datetime -> timestamp

now_1 = "2021-01-05 22:33:29"
temp_1 = dt.strptime(now_1,"%Y-%m-%d %H:%M:%S")
print(temp_1) #str -> datetime
print(temp_1.timestamp()) #str -> timestamp

now_2 = time.time()
temp_2 = dt.fromtimestamp(now_2)
print(temp_2) #timestamp -> datetime
print(temp_2.strftime("%Y-%m-%d %H:%M:%S")) #timestamp -> str

#输出相差的对应日期
while True:
    today = dt.today()
    a = dt.strftime(today,"%Y-%m-%d")
    print(f"今天的日期为：{a}")
    d = int(input("请输入相差的天数："))
    if d == 0:
        print("程序结束")
        break
    gap_day = dt.strftime((today + timedelta(days=d)),"%Y-%m-%d")
    print(f"相差的日期为：{gap_day}")
    print()
